package cn.itcast.n3_Java线程;

import lombok.extern.slf4j.Slf4j;

import static cn.itcast.util.Sleeper.sleep;

/**
 * @program: juc
 * @description:
 * @author: flyduck
 * @create: 2024-08-29 11:45
 **/
@Slf4j(topic = "c.Test16_join方法_有时效的等待")
public class Test16_join方法_有时效的等待 {
    static int r = 0;
    static int r1 = 0;
    static int r2 = 0;

    public static void main(String[] args) throws InterruptedException {
        test3();
    }

    public static void test3() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            sleep(2);
            r1 = 10;
        });

        long start = System.currentTimeMillis();
        t1.start();

        // 线程执行结束会导致 join 结束
        log.debug("join begin");
        t1.join(1500);
        long end = System.currentTimeMillis();
        log.debug("r1: {} r2: {} cost: {}", r1, r2, end - start);//1524
    }


}
